﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;


namespace FormaBedoboNS
{
    /// <summary>
    /// Bill és egér input kezelő osztály
    /// </summary>
    public class Input
    {
        private KeyboardState _currKeyState;
        private KeyboardState _lastKeyState;

        private MouseState _currMouseState;
        private MouseState _lastMouseState;

        private Vector2 _currMousePosition;
        private Vector2 _lastMousePosition;

        /// <summary>
        /// aktuális egér pozíció
        /// </summary>
        public Vector2 mouseCurrentPosition
        {
            get { return _currMousePosition; }
        }
        /// <summary>
        /// egér utolsó pozíciója
        /// </summary>
        public Vector2 mouseLastPosition
        {
            get { return _lastMousePosition; }
        }

        /// <summary>
        /// Update
        /// </summary>
        public void Update()
        {
            _lastKeyState = _currKeyState;
            _currKeyState = Keyboard.GetState();

            _lastMouseState = _currMouseState;
            _currMouseState = Mouse.GetState();
            //Console.WriteLine(m_CurrMouseState);

            _lastMousePosition.X = _currMousePosition.X;
            _lastMousePosition.Y = _currMousePosition.Y;

            _currMousePosition.X = _currMouseState.X;
            _currMousePosition.Y = _currMouseState.Y;
        }
        /// <summary>
        /// egy billentyű le van-e nyomva?
        /// </summary>
        /// <param name="p_Key"></param>
        /// <returns></returns>
        public bool KeyIsPress(Keys p_Key)
        {
            if (_currKeyState.IsKeyDown(p_Key))
                return true;
            return false;
        }
        /// <summary>
        /// egy billentyű most le van-e nyomva, de előzőleg nem volt
        /// </summary>
        /// <param name="p_Key"></param>
        /// <returns></returns>
        public bool KeyIsPressed(Keys p_Key)
        {
            if (_currKeyState.IsKeyDown(p_Key) && !_lastKeyState.IsKeyDown(p_Key))
                return true;
            return false;
        }
        /// <summary>
        /// utoljára ezt a billentyűt nyomták le?
        /// </summary>
        /// <param name="p_Key"></param>
        /// <returns></returns>
        public bool KeyLastIsPress(Keys p_Key)
        {
            if (_lastKeyState.IsKeyDown(p_Key))
                return true;
            return false;
        }

        /// <summary>
        /// utoljára ez a billentyű került lenyomásra, ami előtte nem volt lenyomva?
        /// </summary>
        /// <param name="p_Key"></param>
        /// <returns></returns>
        public bool KeyLastIsPressed(Keys p_Key)
        {
            if (_lastKeyState.IsKeyDown(p_Key) && !_currKeyState.IsKeyDown(p_Key))
                return true;
            return false;
        }

        /// <summary>
        /// MLB down
        /// </summary>
        /// <returns></returns>
        public bool MouseLeftPress()
        {
            if (_currMouseState.LeftButton == ButtonState.Pressed)
                return true;
            return false;
        }
        /// <summary>
        /// LMB lenyomva, de előtte nem volt
        /// </summary>
        /// <returns></returns>
        public bool MouseLeftPressed()
        {
            if (_currMouseState.LeftButton == ButtonState.Pressed && _lastMouseState.LeftButton == ButtonState.Released)
                return true;
            return false;
        }
        /// <summary>
        /// LMB elengedve (korábban le volt nyomva)
        /// </summary>
        /// <returns></returns>
        public bool MouseLeftReleased()
        {
            if (_currMouseState.LeftButton == ButtonState.Released && _lastMouseState.LeftButton == ButtonState.Pressed)
                return true;
            return false;
        }
        /// <summary>
        /// egér pozícióba állítva
        /// </summary>
        /// <param name="p_Position"></param>
        public void SetMousePosition(Vector2 p_Position)
        {
            _currMousePosition = p_Position;
            _lastMousePosition = p_Position;
            Mouse.SetPosition((int)p_Position.X, (int)p_Position.Y);
        }

    }
}
